<template>
    <div class="search">
        <input type="text" v-model="todo.title" ref="title_input" @keyup.enter="addTodoList()">
        <span @click="addTodoList()">+</span>
    </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref} from "vue";
import { addTodo } from '../request/api'
import { v4 as uuidv4 } from 'uuid'
import $bus from '../utils/bus'
let data = reactive({
    todo:{
        id: '',
        iscomplete: false,
        title:''
    }
})
let title_input = ref(null)
let addTodoList = async ()=>{
    data.todo.id = uuidv4()
    let res = await addTodo(data.todo);
    console.log(res);
    (title_input.value as unknown as HTMLInputElement).value = ''
    $bus.emit('fetchtodoList')
    $bus.emit('getState')
}
let { todo } = toRefs(data)
</script>

<style scoped>
.search {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 30px;
}
.search input {
    outline: none;
    background-color: transparent;
    color: white;
    height: 30px;
    border: none;
    width: 80%;
    border-bottom: 1px solid #e3e3e3;
    font-size: 18px;
    padding-left:10px;
}
.search span{
    width: 10%;
    display: inline-block;
    height: 30px;
    background-color: #ff7b85;
    border-radius: 50%;
    text-align: center;
    line-height:30px;
    font-size: 30px;
    color: #181744;
}
.search span:hover {
    background-color: rgb(235, 70, 70);
}
</style> 